﻿using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using Ivory;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Paintball.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Paintball.Libaries
{
    public abstract class Sprite : IDrawableObject
    {
        //Fields
        protected int RenderIndex = Globals.MinLayerIndex;
        private Body Body { get; set; }

        public Rectangle BoundingBox { get; set; }
        public abstract int LayerIndex { get; set; }

        private Vector2 _Origin;
        public Vector2 Origin
        {
            get
            { 
                return _Origin;
            }
            set 
            { 
                _Origin = value;
            }
        }
        
        public float Rotation
        {
            get { return Body.Rotation; }
            set { Body.Rotation = value; }
        }
        
        //Construct
        public Sprite(Rectangle bb)
        {
            this.BoundingBox = bb;
            this.InitalizeBody(this.Body);
            this.Body.UserData = this.GetType();
        }

        //Methods
        protected virtual void InitalizeBody(Body body)
        {
            body = BodyFactory.CreateRectangle(ObjectHolder.GameWorld, BoundingBox.Width, BoundingBox.Height, 1f);
            body.Mass = 1f;
            body.SleepingAllowed = true;            
        }

        public abstract void Draw(SpriteBatch batch, GameTime time);
        public abstract void Update(InputControl input, GameTime time);
        public abstract bool Load();
    }
}
